/*
 * @Author: cl
 * @Description: 泛型
 * @Date: 2023-03-30 11:31:23
 * @LastEditTime: 2023-07-07 14:30:03
 * @FilePath: \jsnode\typescript\genericity.ts
 * @LastEditors: chenli chenli@kcwl.com
 */

/**
 * 箭头函数使用泛型
 * @param val
 * @returns
 */
let setData = <T>(val: T): T => {
  return val;
};
/**
 * 普通函数使用泛型
 * @param val
 * @returns
 */
function setfnData<T>(val: T): T {
  return val;
}
/**
 * 多个泛型
 * @param val
 * @param val2
 * @returns
 */
function setfnTwoParams<T, D>(val: T, val2: D): D {
  return val2;
}

class Animal<T> {
  name: T;
  constructor(name: T) {
    this.name = name;
  }
  action<T>(say: T) {
    console.log(say);
  }
}
let cat = new Animal("cat");
let dog = new Animal(10);
cat.action("mimi");
dog.action('large')

function setASnim<T, D = Animal<T>>(val: T, val2: D): D {
    (val2 as any).action(val)
  return val2;
}

console.log(setASnim('zhanag',dog).action('maomao'));

